package com.notetool.datafetching;

import com.notetool.util.tokenparser.TokenList;

public class QueryMonitor
{
    
    ////////////////////
    // Constructors
    public QueryMonitor ()
    {
        
    }
    
    ////////////////////
    // Public methods
    public Query buildQuery (TokenList tokens) throws QueryInitException, QueryStoppedException 
    {
        return new Query.buildFrom (tokens, this);
        // buildFrom creates the node, throws QueryInit and MonitorStopped
        // instanciate Query and passes built node as param
        
        // Replace the inheritance crap with actual IParserMonitor and IQueryMonitor
        // It means we dont need this class anymore...
        // We'll just need the QueryManager class
        // It'll implement parserCheckpoint and queryCheckpoint which will respectively throw ParserStoppedEx and QueryStoppedEx
        // We'll just have a runQuery(String) method which will call the parser (with self as ParserMonitor argument), then Query.buildFrom (with self as QueryMonitor argument), then query.run (with self as QueryMonitor argument).
        // In the checkpoints, if the thread id == event thread, instantly return, never throw exception...
        // We also have a runAsyncQuey (String) which builds an QueryThread (passing it the string), which in turn calls QueryManager.runQuery ();
    }
    
    public NoteSet runQuery (Query query) throws QueryExecException, QueryStoppedException
    {
        // query.run (this);
    }
    
    ////////////////////
    // Protected methods
    protected void checkpoint () throws QueryStoppedException
    {
        // If threadid == eventthread
        // return
        
    }
    
}


// We have QueryManager
// QueryManager has Parser and Monitor
// QueryManager has a runAsync (String qry) method
// WHen that method is called, a QueryThread is created and the monitor is passed as param. The run of that thread runs the Parser and Monitor's shit
// the run of the thread runs the query like Monitor.runQuery... the checkpoints won't raise exceptions if we're running in the event thread. otherwise, they will if our thread id isn't the current query runner ID
// When the run finishes, we callback the QueryManager and lock through a mutex. if the query ID is the active one, we pop
// our query result onto the event thread... if not, we just end the thread without anything else...